package OPeration;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOPeration
        implements IOPeration {//新增图书
    @Override
    public void work(BookList bookList) {
        System.out.println("add~~");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要新增的书名:");
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(name.equals(book.getName())) {
                System.out.println("书架中已经有此书,暂不添加...");
                System.out.println(book);
                return;
            }
        }
        System.out.println("请输入你要新增书的作者:");
        String author = scanner.nextLine();
        System.out.println("请输入你要新增书的价格:");
        int price = scanner.nextInt();
        System.out.println("请输入你要新增书的类型:");
        scanner.nextLine();
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        bookList.setBooks(book,currentSize);
        bookList.setUsedSize(currentSize+1);
    }
}
